//
//  AINavigationViewController.m
//  AI
//
//  Created by zjhc on 2018/1/8.
//  Copyright © 2018年 zjhc. All rights reserved.
//

#import "AINavigationViewController.h"

@implementation AINavigationViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.edgesForExtendedLayout = UIRectEdgeNone;
 self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    [super pushViewController:viewController animated:animated];
    if (viewController.navigationItem.leftBarButtonItem == nil && [self.viewControllers count] > 1) {
        viewController.navigationItem.leftBarButtonItem =[self createBackButton];
    }
}

-(UIBarButtonItem*) createBackButton{
    
    UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
    b.frame =  CGRectMake(0, 0, 50, 44);
    //    [b setBackgroundColor:[UIColor redColor]];
    UIImageView * btniv = [[UIImageView alloc]initWithFrame:CGRectMake(0, (self.navigationBar.frame.size.height - 20)/2, 13, 20)];
    btniv.userInteractionEnabled = YES;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onBack)];
    [btniv addGestureRecognizer:tap];
    UIImage*backImg=[UIImage imageNamed:@"title_back"];
    [btniv setImage:backImg];
    
    //    [b setBackgroundImage:backImg forState:UIControlStateNormal];
    [b addSubview:btniv];
    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:b];
    [b addTarget:self action:@selector(onBack) forControlEvents:UIControlEventTouchUpInside];
    return btn;
}
-(void)onBack{
    [super popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
